package top.glike.ssl.auto.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.glike.ssl.auto.domain.SslCertSyncLog;
import top.glike.ssl.auto.mapper.SslCertSyncLogMapper;
import top.glike.ssl.auto.service.ISslCertSyncLogService;

import java.util.Date;
import java.util.List;

/**
 * 同步记录Service业务层处理
 *
 * @author Sophia
 * @date 2025-10-12
 */
@Service
public class SslCertSyncLogServiceImpl implements ISslCertSyncLogService {
    @Autowired
    private SslCertSyncLogMapper sslCertSyncLogMapper;

    /**
     * 查询同步记录
     *
     * @param id 同步记录主键
     * @return 同步记录
     */
    @Override
    public SslCertSyncLog selectSslCertSyncLogById(Long id) {
        return sslCertSyncLogMapper.selectSslCertSyncLogById(id);
    }

    /**
     * 查询同步记录列表
     *
     * @param sslCertSyncLog 同步记录
     * @return 同步记录
     */
    @Override
    public List<SslCertSyncLog> selectSslCertSyncLogList(SslCertSyncLog sslCertSyncLog) {
        return sslCertSyncLogMapper.selectSslCertSyncLogList(sslCertSyncLog);
    }

    /**
     * 新增同步记录
     *
     * @param sslCertSyncLog 同步记录
     * @return 结果
     */
    @Override
    public int insertSslCertSyncLog(SslCertSyncLog sslCertSyncLog) {
        sslCertSyncLog.setUpdateTime(new Date());
        sslCertSyncLog.setCreatedTime(sslCertSyncLog.getUpdateTime());
        return sslCertSyncLogMapper.insertSslCertSyncLog(sslCertSyncLog);
    }

    /**
     * 修改同步记录
     *
     * @param sslCertSyncLog 同步记录
     * @return 结果
     */
    @Override
    public int updateSslCertSyncLog(SslCertSyncLog sslCertSyncLog) {
        sslCertSyncLog.setUpdateTime(new Date());
        return sslCertSyncLogMapper.updateSslCertSyncLog(sslCertSyncLog);
    }

    /**
     * 批量删除同步记录
     *
     * @param ids 需要删除的同步记录主键
     * @return 结果
     */
    @Override
    public int deleteSslCertSyncLogByIds(Long[] ids) {
        return sslCertSyncLogMapper.deleteSslCertSyncLogByIds(ids);
    }

    /**
     * 删除同步记录信息
     *
     * @param id 同步记录主键
     * @return 结果
     */
    @Override
    public int deleteSslCertSyncLogById(Long id) {
        return sslCertSyncLogMapper.deleteSslCertSyncLogById(id);
    }

    @Override
    public SslCertSyncLog saveSslServer(SslCertSyncLog sslCertSyncLog) {
        if (sslCertSyncLog.getId() != null) {
            sslCertSyncLog.setUpdateTime(new Date());
            sslCertSyncLogMapper.updateSslCertSyncLog(sslCertSyncLog);
        } else {
            sslCertSyncLog.setUpdateTime(new Date());
            sslCertSyncLog.setCreatedTime(sslCertSyncLog.getUpdateTime());
            sslCertSyncLogMapper.insertSslCertSyncLog(sslCertSyncLog);
        }
        return sslCertSyncLog;
    }

}
